package com.qyhl.question.question.rank;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.flyco.tablayout.SlidingTabLayout;
import com.gyf.immersionbar.ImmersionBar;
import com.qyhl.question.R;
import com.qyhl.question.R2;
import com.qyhl.webtv.basiclib.base.BaseActivity;
import com.qyhl.webtv.basiclib.base.BaseIViewPresenter;
import com.qyhl.webtv.commonlib.constant.ARouterPathConstant;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

@Route(path = ARouterPathConstant.QUESTION_RANK)
public class QuestionRankActivity extends BaseActivity {
    @BindView(R2.id.tab_layout)
    SlidingTabLayout tabLayout;
    @BindView(R2.id.viewPager)
    ViewPager viewPager;

    @Override
    protected int getContentView() {
        return R.layout.question_activity_rank;
    }

    @Override
    protected void setImmersionBar(ImmersionBar mImmersionBar) {
        mImmersionBar.fullScreen(true).statusBarDarkFont(false).init();
    }

    @Override
    protected BaseIViewPresenter initBaseIViewPresenter() {
        return null;
    }

    @Override
    protected void init() {
        List<String> nameList = new ArrayList<>();
        List<Fragment> fragments = new ArrayList<>();
        String subjectId = getIntent().getStringExtra("id");

        nameList.add("实时榜单");
        nameList.add("上月榜单");

        fragments.add(QuestionRankFragment.newInstance(subjectId, "realtime"));
        fragments.add(QuestionRankFragment.newInstance(subjectId, "lastMonth"));

        viewPager.setAdapter(new Adapter(this.getSupportFragmentManager(), fragments, nameList));
        tabLayout.setViewPager(viewPager);
    }

    @Override
    protected void setListener() {

    }

    @OnClick(R2.id.back_btn)
    public void onViewClicked() {
        finish();
    }

    class Adapter extends FragmentPagerAdapter {
        private List<Fragment> fragmentList;
        private List<String> names;

        Adapter(FragmentManager fm, List<Fragment> fragmentList, List<String> names) {
            super(fm);
            this.fragmentList = fragmentList;
            this.names = names;
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return names.get(position);
        }
    }

}
